home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / csmplr.zip / CSMPLR.NEW < prev   
Text File  |  1990-06-18  |  28KB  |  1,173 lines

  1. /*   1: 2.1.1.2  Backslash-splicing */
  2. #include <stdio.h>
  3. main()
  4.     {
  5.     int start = (printf("started\n"));
  6.     i\
  7. n\
  8. t\
  9.     i = 3;
  10.     if (i == 3)
  11.         printf("success\n");
  12.     return 0;
  13.     }
  14.  
  15. /*   2: 2.1.1.2  Phases of translation */
  16.     /* #define NOTDEFINED 1 */
  17. ??=include/* SPACE */<stddef.h>
  18. #\
  19. i\
  20. f\
  21.  !\
  22. defined(NOTDEFINED)
  23. #define UI unsigned in??/
  24. t
  25.  
  26. #define/* SPACE */PCHAR(/*SPACE*/x/*SPACE*/)/* SPACE */char x/*SPACE*/??(??)
  27.  
  28. #endif
  29. UI/* SPACE */Ui/* SPACE */=/* SPACE */'\
  30. \n' ;
  31. PCHAR(Pc) = "string1??/
  32. #\
  33. "\
  34. "string2" ;
  35. #include <stdio.h>
  36. main()
  37.     {
  38.     int start = (printf("started\n"));
  39.     if (Ui == '\n' && Pc[8] == 's')
  40.         printf("success\n");
  41.     return 0;
  42.     }
  43.  
  44. /*   3: 2.2.1.1  Trigraphs */
  45. #include <stdio.h>
  46. main()
  47.     {
  48.     int start = (printf("started\n"));
  49.     ??<
  50.     int i = 3;
  51.     if (i == 3)
  52.         printf("success\n");
  53.     ??>
  54.     return 0;
  55.     }
  56.  
  57. /*   4: 2.2.4.2  <float.h> -- e.g., DBL_DIG >= 10  [87/03]   */
  58. #include <float.h>
  59. #include <stdio.h>
  60. main()
  61.     {
  62.     int start = (printf("started\n"));
  63.     if (DBL_DIG >= 10)
  64.         printf("success\n");
  65.     return 0;
  66.     }
  67.  
  68. /*   5: 2.2.4.2  <limits.h> -- e.g., has MB_LEN_MAX  [87/12]   */
  69. #include <limits.h>
  70. #include <stdio.h>
  71. main()
  72.     {
  73.     int start = (printf("started\n"));
  74.     if (CHAR_BIT >= 8 && INT_MIN <= -32767 && MB_LEN_MAX >= 1)
  75.         printf("success\n");
  76.     return 0;
  77.     }
  78.  
  79. /*   6: 3.1.2    Internal identifier significance at least 31 characters */
  80. #include <stdio.h>
  81. main()
  82.     {
  83.     int start = (printf("started\n"));
  84.     int a23456789012345678901234567890a = 3;
  85.     int a23456789012345678901234567890b = 4;
  86.     if (a23456789012345678901234567890a == 3 &&
  87.         a23456789012345678901234567890b == 4)
  88.         printf("success\n");
  89.     return 0;
  90.     }
  91. /*   7: 3.1.2.2  Scope rules: file, function, prototype, and block */
  92. #include <stdio.h>
  93. int x = 2;          /* this x has file scope */
  94. main()
  95.     {
  96.     int start = (printf("started\n"));
  97.     int f();
  98.  
  99.     if (f() == 1)
  100.         printf("success\n");
  101.     return 0;
  102.     }
  103. int f()
  104.     {
  105.     int c(int x);   /* this x has prototype scope */
  106.     if (x != 2)
  107.         exit(2);
  108.     else
  109.         {
  110.         char x = 3; /* this x has block scope */
  111.         if (x != 3)
  112.             exit(3);
  113.         goto x;
  114.         exit(4);
  115.         }
  116. x:                  /* this x has function scope */
  117.     return 1;
  118.     }
  119. /*   8: 3.1.2.3  Name space rules: variables, labels, tags, and members */
  120. #include <stdio.h>
  121. #include <stdlib.h>
  122. main()
  123.     {
  124.     int start = (printf("started\n"));
  125.     static struct x { int x; } x = {6};
  126.     goto x;
  127.     exit(0);
  128. x:
  129.     if (x.x == 6) printf("success\n");
  130.     return 0;
  131.     }
  132. /*   9: 3.1.2.3  Unique member name spaces */
  133. #include <stdio.h>
  134. main()
  135.     {
  136.     int start = (printf("started\n"));
  137.     static struct a { char x; } a = {7};
  138.     static struct b { double x; } b = {8};
  139.     if (a.x == 7 && b.x == 8)
  140.         printf("success\n");
  141.     return 0;
  142.     }
  143. /*  10: 3.1.2.5  long double  (even if same size as  double  ) */
  144. #include <stdio.h>
  145. main()
  146.     {
  147.     int start = (printf("started\n"));
  148.     long double x = 4.L;
  149.     if (x == 4L)
  150.         printf("success\n");
  151.     return 0;
  152.     }
  153. /*  11: 3.1.2.5  all unsigned types */
  154. #include <stdio.h>
  155. main()
  156.     {
  157.     int start = (printf("started\n"));
  158.     unsigned char uc = 1;
  159.     unsigned short us = 2;
  160.     unsigned int ui = 4;
  161.     unsigned long ul = 7;
  162.     if (ul - ui - us - uc == 0)
  163.         printf("success\n");
  164.     return 0;
  165.     }
  166. /*  12: 3.1.2.5  signed char */
  167. #include <stdio.h>
  168. main()
  169.     {
  170.     int start = (printf("started\n"));
  171.     signed char sc = -1;
  172.     if (8 * sc == -8)
  173.         printf("success\n");
  174.     return 0;
  175.     }
  176. /*  13: 3.1.2.6  Type-compatibility rules  [87/12] */
  177. #include <stdio.h>
  178. main()
  179.     {
  180.     int start = (printf("started\n"));
  181.     const int *f();
  182.     if (*f(&start) == start)
  183.         printf("success\n");
  184.     return 0;
  185.     }
  186. int signed const *f();
  187. signed int const *f(int *);
  188. int const *f(int *pi)
  189.     {
  190.     return pi;
  191.     }
  192. /*  14: 3.1.3.2  constants:  U,  L,  unsignedness rules */
  193. #include <stdio.h>
  194. main()
  195.     {
  196.     int start = (printf("started\n"));
  197.     if (-1 < 1u)
  198.         ;
  199.     else if (1UL != 1ul)
  200.         ;
  201.     else
  202.         printf("success\n");
  203.     return 0;
  204.     }
  205. /*  15: 3.1.3.4  character constants with more than one char */
  206. #include <stdio.h>
  207. main()
  208.     {
  209.     int start = (printf("started\n"));
  210.     int c = 'abcd';
  211.     printf("success\n");
  212.     return 0;
  213.     }
  214. /*  16: 3.1.3.4  '\xFF' */
  215. #include <stdio.h>
  216. main()
  217.     {
  218.     int start = (printf("started\n"));
  219.     if ('\xFF' == (char)0xFF)
  220.         printf("success\n");
  221.     return 0;
  222.     }
  223. /*  17: 3.1.3.4  '\a'  '\v'   */
  224. #include <stdio.h>
  225. main()
  226.     {
  227.     int start = (printf("started\n"));
  228.     if ('\a' != 'a' && '\v' != 'v')
  229.         printf("success\n");
  230.     return 0;
  231.     }
  232. /*  18: 3.1.3.4  Wide-characters: L'x', L"x", wc*, mb*, wchar_t  [87/12] */
  233. #include <stdio.h>
  234. main()
  235.     {
  236.     int start = (printf("started\n"));
  237.     int f();
  238.     if (f() == 2)
  239.         printf("success\n");
  240.     return 0;
  241.     }
  242. #include <stdlib.h>
  243. int f()
  244.     {
  245.     wchar_t wc = L'\0';
  246.     wchar_t wcs[] = L"";
  247.     char s[2];
  248.     if (wc == 0 && wctomb(s, wc) == 1)
  249.         return 2;
  250.     return 0;
  251.     }
  252. /*  19: 3.1.5    "Old-style" assignment-operators are gone */
  253. #include <stdio.h>
  254. main()
  255.     {
  256.     int start = (printf("started\n"));
  257.     short n = 3;
  258.     short m = 2;
  259.     n=-m;
  260.     if (n == -2)
  261.         printf("success\n");
  262.     return 0;
  263.     }
  264. /*  20: 3.2.1.1  "Value-preserving" integer conversion rules */
  265. #include <stdio.h>
  266. main()
  267.     {
  268.     int start = (printf("started\n"));
  269.     if (sizeof(int) > sizeof(char))
  270.         {
  271.         unsigned char uc1 = 1;
  272.         unsigned char uc2 = 2;
  273.         if (uc1 - uc2 < 0)
  274.             printf("success\n");
  275.         }
  276.     else
  277.         printf("success\n");    /* conforming, but weird */
  278.     return 0;
  279.     }
  280. /*  21: 3.2.1.5  Expressions with  float  operands have  float  type */
  281. #include <stdio.h>
  282. main()
  283.     {
  284.     int start = (printf("started\n"));
  285.     float x, y;
  286.     if (sizeof(x + y) == sizeof(float))
  287.         printf("success\n");
  288.     return 0;
  289.     }
  290. /*  22: 3.2.2.1  Address-of on array and function */
  291. #include <stdio.h>
  292. main()
  293.     {
  294.     int start = (printf("started\n"));
  295.     char a[10];
  296.     if (sizeof(*&a) == 10 && main == &main)
  297.         printf("success\n");
  298.     return 0;
  299.     }
  300. /*  23: 3.2.2.1  Call-through-pointer  (*pkg.fn)()  may be written  pkg.fn() */
  301. #include <stdio.h>
  302. main()
  303.     {
  304.     int start = (printf("started\n"));
  305.     int f();
  306.     int (*pf)() = f;
  307.     if (pf() == 5)
  308.         printf("success\n");
  309.     return 0;
  310.     }
  311. int f()
  312.     {
  313.     return 5;
  314.     }
  315. /*  24: 3.2.2.2  OK to cast void to void  [87/09] */
  316. #include <stdio.h>
  317. main()
  318.     {
  319.     int start = (printf("started\n"));
  320.     void f();
  321.     (void)f();
  322.     return 0;
  323.     }
  324. void f()
  325.     {
  326.     printf("success\n");
  327.     }
  328. /*  25: 3.2.2.3  Generic pointers:  void * */
  329. #include <stdio.h>
  330. main()
  331.     {
  332.     int start = (printf("started\n"));
  333.     void *gp;
  334.     float x, y;
  335.     gp = &x;
  336.     if (gp == &x && gp != &y)
  337.         printf("success\n");
  338.     return 0;
  339.     }
  340. /*  26: 3.3.2.2  prototype-with-default-sizes is compatible with no-prototype */
  341. #include <stdio.h>
  342. int f();
  343. int f(int);
  344. main()
  345.     {
  346.     int start = (printf("started\n"));
  347.     if (f(0) == 2)
  348.         printf("success\n");
  349.     return 0;
  350.     }
  351. int f(int i)
  352.     {
  353.     return i + 2;
  354.     }
  355. /*  27: 3.3.2.2  Calling a prototyped function causes conversion (as if by ass't) */
  356. #include <stdio.h>
  357. main()
  358.     {
  359.     int start = (printf("started\n"));
  360.     double f(double);
  361.     if (f(2) == -2.0)
  362.         printf("success\n");
  363.     return 0;
  364.     }
  365. double f(double x)
  366.     {
  367.     return -x;
  368.     }
  369. /*  28: 3.3.3.3  Unary plus */
  370. #include <stdio.h>
  371. main()
  372.     {
  373.     int start = (printf("started\n"));
  374.     int i = 3;
  375.     if (+i == 3)
  376.         printf("success\n");
  377.     return 0;
  378.     }
  379. /*  29: 3.3.3.4  sizeof applies to any rvalue expression */
  380. #include <stdio.h>
  381. main()
  382.     {
  383.     int start = (printf("started\n"));
  384.     int i;
  385.     if (sizeof(i+1) == sizeof(int))
  386.         printf("success\n");
  387.     return 0;
  388.     }
  389. /*  30: 3.3.16.1 Structure assignment, return, and argument-passing */
  390. #include <stdio.h>
  391. static struct x { int i; } a = {1};
  392. main()
  393.     {
  394.     int start = (printf("started\n"));
  395.     struct x b;
  396.     struct x c;
  397.     struct x f();
  398.     b = a;
  399.     c = f(b);
  400.     if (c.i == 1)
  401.         printf("success\n");
  402.     return 0;
  403.     }
  404. struct x f(v)
  405. struct x v;
  406.     {
  407.     return v;
  408.     }
  409. /*  31: 3.5.2.2  enum and tag-scope rules  [87/03] */
  410. #include <stdio.h>
  411. main()
  412.     {
  413.     int start = (printf("started\n"));
  414.     enum b { bm2=-2, b0=bm2+2, b1, b2 } b = b2;
  415.     switch (b)
  416.         {
  417.     case b2:
  418.         printf("success\n");
  419.     default:
  420.         ;
  421.         }
  422.     return 0;
  423.     }
  424. /*  32: 3.5.2.3  struct sb;  introduces a new scope  */
  425. #include <stdio.h>
  426. struct sb { double x; } bx = { 9.9 };
  427. main()
  428.     {
  429.     int start = (printf("started\n"));
  430.     struct sb;
  431.     struct sa { struct sb *pb; int i; } a;
  432.     struct sb { struct sa *pa; int i; } b;
  433.     b.i = 13;
  434.     a.pb = &b;
  435.     if (a.pb->i == 13)
  436.         printf("success\n");
  437.     return 0;
  438.     }
  439. /*  33: 3.5.3    const is independent qualifier of e.g. struct type  */
  440. #include <stdio.h>
  441. main()
  442.     {
  443.     int start = (printf("started\n"));
  444.     const struct sa { int i; } csa;
  445.     const struct sa *pcsa = &csa;
  446.     struct sa sa2;
  447.     sa2.i = 9;
  448.     if (sa2.i == 9 && pcsa == &csa)
  449.         printf("success\n");
  450.     return 0;
  451.     }
  452. /*  34: 3.5.3    volatile preserves auto values modified after setjmp  */
  453. #include <stdio.h>
  454. #include <setjmp.h>
  455. jmp_buf env;
  456. main()
  457.     {
  458.     int start = (printf("started\n"));
  459.     volatile int n = 2;
  460.     if (setjmp(env) == 0)
  461.         {
  462.         n = 6;
  463.         longjmp(env, 1);
  464.         }
  465.     else
  466.         {
  467.         if (n == 6)
  468.             printf("success\n");
  469.         }
  470.     return 0;
  471.     }
  472. /*  35: 3.5.4    ellipsis -- e.g. int printf(const char *, ...); */
  473. #include <stdio.h>
  474. main()
  475.     {
  476.     int start = (printf("started\n"));
  477.     int printf(const char *fmt, ...);
  478.     printf("success\n");
  479.     return 0;
  480.     }
  481. /*  36: 3.5.4    prototypes (for declarations) */
  482. #include <stdio.h>
  483. main()
  484.     {
  485.     int start = (printf("started\n"));
  486.     int f(int);
  487.     if (f(0) == 4)
  488.         printf("success\n");
  489.     return 0;
  490.     }
  491. int f(i)
  492. int i;
  493.     {
  494.     return 4;
  495.     }
  496. /*  37: 3.5.4    prototypes (for "new-style" definitions) */
  497. #include <stdio.h>
  498. main()
  499.     {
  500.     int start = (printf("started\n"));
  501.     short f(short);
  502.     if (f(0) == 4)
  503.         printf("success\n");
  504.     return 0;
  505.     }
  506. short f(short i)
  507.     {
  508.     return 4;
  509.     }
  510. /*  38: 3.5.7    Elided-braces rules (as in K&R, not in PCC) */
  511. #include <stdio.h>
  512. struct sa { int a[3]; int b; } asa[2] = { {1}, 2 }; /* from Std */
  513. main()
  514.     {
  515.     int start = (printf("started\n"));
  516.     if (asa[0].a[0] == 1 && asa[1].a[0] == 2)
  517.         printf("success\n");
  518.     return 0;
  519.     }
  520. /*  39: 3.5.7    auto aggregate initializers */
  521. #include <stdio.h>
  522. main()
  523.     {
  524.     int start = (printf("started\n"));
  525.     char msg[20] = {"success\n"};
  526.     printf(msg);
  527.     return 0;
  528.     }
  529. /*  40: 3.5.7    union initializers (via first member) */
  530. #include <stdio.h>
  531. main()
  532.     {
  533.     int start = (printf("started\n"));
  534.     union { char *msg; double d; } md = {"success\n"};
  535.     printf(md.msg);
  536.     return 0;
  537.     }
  538. /*  41: 3.6.4.2  long-size switch labels */
  539. #include <stdio.h>
  540. main()
  541.     {
  542.     int start = (printf("started\n"));
  543.     long lnum = 2;
  544.     switch (lnum)
  545.         {
  546.     default:
  547.         exit(3);
  548.     case 2L:
  549.         printf("success\n");
  550.         }
  551.     return 0;
  552.     }
  553. /*  42: 3.7.2    Tentative definition for static */
  554. #include <stdio.h>
  555. static struct sa { struct sb *pb; int i; } a;
  556. static struct sb { struct sa *pa; int i; } b = { &a, 13 };
  557. static struct sa  a = { &b, 11 };
  558. main()
  559.     {
  560.     int start = (printf("started\n"));
  561.     if (a.i == 11 && b.pa->pb->i == 13)
  562.         printf("success\n");
  563.     return 0;
  564.     }
  565. /*  43: 3.8.1    #if defined, #elif */
  566. #define DEF 1
  567. #include <stdio.h>
  568. main()
  569.     {
  570.     int start = (printf("started\n"));
  571. #ifdef NODEF
  572.     exit(3);
  573. #elif defined(DEF)
  574.     printf("success\n");
  575. #endif
  576.     return 0;
  577.     }
  578. /*  44: 3.8.1    no syntax-checking of skipped groups */
  579. #include <stdio.h>
  580. main()
  581.     {
  582.     int start = (printf("started\n"));
  583. #if NODEF
  584.     L'x' 1.2.3.4.E--xx @$*** JUNK (((
  585. #else
  586.     printf("success\n");
  587. #endif
  588.     return 0;
  589.     }
  590. /*  45: 3.8.2    #include macro-name */
  591. #define STDIO <stdio.h>
  592. #include STDIO
  593. main()
  594.     {
  595.     int start = (printf("started\n"));
  596.     char *p = NULL;
  597.     printf("success\n");
  598.     return 0;
  599.     }
  600. /*  46: 3.8.3    "hiding" of macro names */
  601. #include <stdio.h>
  602. int f(a, b, c)
  603. int a, b, c;
  604.     {
  605.     return c+4;
  606.     }
  607. #define f(a, b) f(a, b, 0)
  608. main()
  609.     {
  610.     int start = (printf("started\n"));
  611.     int a=1, b=2;
  612.     if (f(a, b) == 4)
  613.         printf("success\n");
  614.     return 0;
  615.     }
  616. /*  47: 3.8.3    benign re-definition allowed */
  617. #include <stdio.h>
  618. main()
  619.     {
  620.     int start = (printf("started\n"));
  621. #define A 1 + 1
  622. #define A   1  +  1
  623. #define A 1 /**/ + /**/ 1
  624.     if (A == 2)
  625.         printf("success\n");
  626.     return 0;
  627.     }
  628. /*  48: 3.8.3    Preprocessor catenation and string-izing */
  629. #include <stdio.h>
  630. #define STR(a) NXSTR(a)
  631. #define NXSTR(a) #a
  632. #define CAT(a, b) NXCAT(a, b)
  633. #define NXCAT(a, b) a ## b
  634. #define A 1
  635. #define B 2
  636. #define AB 5
  637. main()
  638.     {
  639.     int start = (printf("started\n"));
  640.     if (STR(A)[0] == '1' &&
  641.         NXSTR(B)[0] == 'B' &&
  642.         CAT(A, B) == 12 &&
  643.         NXCAT(A, B) == 5)
  644.         printf("success\n");
  645.     return 0;
  646.     }
  647. /*  49: 3.8.5    New preprocessor directive #pragma */
  648. #pragma IGNORE THIS NON-EXISTENT PRAGMA
  649. #include <stdio.h>
  650. main()
  651.     {
  652.     int start = (printf("started\n"));
  653.     printf("success\n");
  654.     return 0;
  655.     }
  656. /*  50: 3.8.8    Predefined macro names */
  657. #include <stdio.h>
  658. main()
  659.     {
  660.     int start = (printf("started\n"));
  661.     if (__DATE__[7] == '1' &&
  662.         __TIME__[2] == ':' &&
  663.         __FILE__[0] != '\0' &&
  664.         __LINE__ > 6 &&
  665.         __STDC__ == 1)
  666.         printf("success\n");
  667.     return 0;
  668.     }
  669. /*  51: 4.1.3    <errno.h>  [87/03]  */
  670. #include <errno.h>
  671. #include <stdio.h>
  672. main()
  673.     {
  674.     int errno_init = errno;
  675.     int start = (printf("started\n"));
  676.     if (errno_init == 0)
  677.         printf("success\n");
  678.     return 0;
  679.     }
  680.  
  681. /*  52: 4.1.5    <stddef.h> -- e.g. offsetof on nested struct member  [88/04] */
  682. #include <stddef.h>
  683. #include <stdio.h>
  684. main()
  685.     {
  686.     int start = (printf("started\n"));
  687.     struct x { struct y { char c; } y; int z; } x;
  688.     if (offsetof(struct x, y.c) == 0)
  689.         printf("success\n");
  690.     return 0;
  691.     }
  692.  
  693. /*  53: 4.2      <assert.h> is a void expression  [87/12] */
  694. #include <assert.h>
  695. #include <stdio.h>
  696. main()
  697.     {
  698.     int start = (printf("started\n"));
  699.     0, assert(1 == 1);
  700.     printf("success\n");
  701.     return 0;
  702.     }
  703.  
  704. /*  54: 4.3      <ctype.h>  */
  705. #include <ctype.h>
  706. #include <stdio.h>
  707. main()
  708.     {
  709.     int start = (printf("started\n"));
  710.     if (isalpha('a'))
  711.         printf("success\n");
  712.     return 0;
  713.     }
  714.  
  715. /*  55: 4.4      <locale.h> -- e.g., initial locale is "C" */
  716. #include <locale.h>
  717. #include <string.h>
  718. #include <stdio.h>
  719. main()
  720.     {
  721.     int start = (printf("started\n"));
  722.     char initial_locale[100];
  723.     strncpy(initial_locale, setlocale(LC_ALL, NULL), 100);
  724.     setlocale(LC_ALL, "C");
  725.     if (LC_ALL != LC_COLLATE &&
  726.         strncmp(setlocale(LC_ALL, NULL), initial_locale, 100) == 0)
  727.         printf("success\n");
  728.     return 0;
  729.     }
  730.  
  731. /*  56: 4.4      localeconv, LC_CURRENCY, negative_sign  [88/04] */
  732. #include <locale.h>
  733. #include <stddef.h>
  734. #include <stdio.h>
  735. main()
  736.     {
  737.     int start = (printf("started\n"));
  738.     struct lconv *plc;
  739.     plc = localeconv();
  740.     if (plc->negative_sign[0] == '\0') /* default "C" value is "" */
  741.         printf("success\n");
  742.     return 0;
  743.     }
  744.  
  745. /*  57: 4.5      <math.h>   */
  746. #include <math.h>
  747. #include <stdio.h>
  748. main()
  749.     {
  750.     int start = (printf("started\n"));
  751.     if (HUGE_VAL != 0.0)
  752.         printf("success\n");
  753.     return 0;
  754.     }
  755.  
  756. /*  58: 4.5.1    Math library sets errno when required */
  757. #include <math.h>
  758. #include <errno.h>
  759. #include <stdio.h>
  760. main()
  761.     {
  762.     int start = (printf("started\n"));
  763.     asin(10.);
  764.     if (errno == EDOM)
  765.         printf("success\n");
  766.     return 0;
  767.     }
  768.  
  769. /*  59: 4.6      <setjmp.h> */
  770. #include <setjmp.h>
  771. #include <stdio.h>
  772. main()
  773.     {
  774.     int start = (printf("started\n"));
  775.     jmp_buf buf;
  776.     if (setjmp(buf) == 0)
  777.         printf("success\n");
  778.     return 0;
  779.     }
  780.  
  781. /*  60: 4.7      <signal.h> */
  782. #include <signal.h>
  783. #include <stdio.h>
  784. void func(int sig)
  785.     {
  786.     if (sig == SIGINT)
  787.         printf("success\n");
  788.     }
  789. main()
  790.     {
  791.     int start = (printf("started\n"));
  792.     signal(SIGINT, func);
  793.     raise(SIGINT);
  794.     return 0;
  795.     }
  796.  
  797. /*  61: 4.8      <stdarg.h> */
  798. #include <stdarg.h>
  799. #include <stdio.h>
  800. func(int nargs, ...)
  801.     {
  802.     va_list ap;
  803.     double d;
  804.     int i;
  805.     va_start(ap, nargs);
  806.     d = va_arg(ap, double);
  807.     if (d == 1.1 && va_arg(ap, int) == 7)
  808.         printf("success\n");
  809.     va_end(ap);
  810.     }
  811. main()
  812.     {
  813.     int start = (printf("started\n"));
  814.     func(2, 1.1, 7);
  815.     return 0;
  816.     }
  817.  
  818. /*  62: 4.9      <stdio.h> -- e.g., OK to include more than once  */
  819. #include <stdio.h>
  820. #include <stdio.h>
  821. main()
  822.     {
  823.     int start = (printf("started\n"));
  824.     if (BUFSIZ >= 256 && TMP_MAX >= 25)
  825.         printf("success\n");
  826.     return 0;
  827.     }
  828.  
  829. /*  63: 4.9.1    In <stdio.h>: FOPEN_MAX  and  FILENAME_MAX  [87/12] */
  830. #include <stdio.h>
  831. main()
  832.     {
  833.     int start = (printf("started\n"));
  834.     if (FOPEN_MAX > 0 && FILENAME_MAX > 0)
  835.         printf("success\n");
  836.     return 0;
  837.     }
  838.  
  839. /*  64: 4.9.2    Stream and file semantics: opening, seeking, text-binary */
  840. #include <stdio.h>
  841. main()
  842.     {
  843.     int start = (printf("started\n"));
  844.     char name[1000];
  845.     FILE *f;
  846.     tmpnam(name);
  847.     f = fopen(name, "w+b");
  848.     fputc(1, f);
  849.     fputc(2, f);
  850.     rewind(f);
  851.     if (fgetc(f) == 1 &&  fgetc(f) == 2)
  852.         printf("success\n");
  853.     return 0;
  854.     }
  855.  
  856. /*  65: 4.9.4    remove, rename  */
  857. #include <stdio.h>
  858. char old[1000];
  859. char new[1000];
  860. main()
  861.     {
  862.     int start = (printf("started\n"));
  863.     FILE *f;
  864.     tmpnam(old);
  865.     tmpnam(new);
  866.     f = fopen(old, "w");
  867.     fputc('a', f);
  868.     fclose(f);
  869.     rename(old, new);
  870.     if (fopen(old, "r") == NULL)
  871.         printf("success\n");
  872.     remove(new);
  873.     return 0;
  874.     }
  875.  
  876. /*  66: 4.9.6    full printf/scanf  to new exact spec */
  877. #include <stdio.h>
  878. main()
  879.     {
  880.     int start = (printf("started\n"));
  881.     char buf[10];
  882.     union { struct { float f; char c; } s; double d; } u;
  883.     u.s.c = 'a';
  884.     sscanf("123.", "%E", &u.s.f);
  885.     sprintf(buf, "%.0d", 0);
  886.     if (u.s.f == 123. && u.s.c == 'a' && buf[0] == '\0')
  887.         printf("success\n");
  888.     return 0;
  889.     }
  890.  
  891. /*  67: 4.9.6    scanf and ungetc push-back independently  [87/12] */
  892. #include <stdio.h>
  893. char name[1000];
  894. main()
  895.     {
  896.     int start = (printf("started\n"));
  897.     FILE *f;
  898.     int i, j;
  899.     tmpnam(name);
  900.     f = fopen(name, "w+");
  901.     fprintf(f, "123 456\n");
  902.     rewind(f);
  903.     fscanf(f, "%d", &i);
  904.     ungetc('9', f);
  905.     fscanf(f, "%d", &j);
  906.     if (i == 123 && j == 9)
  907.         printf("success\n");
  908.     fclose(f);
  909.     remove(name);
  910.     return 0;
  911.     }
  912.  
  913. /*  68: 4.9.6    v*printf, v*scanf  */
  914. #include <stdarg.h>
  915. #include <stdio.h>
  916. void print(char *s, char *format, ...)
  917.     {
  918.     va_list args;
  919.     va_start(args, format);
  920.     vsprintf(s, format, args);
  921.     va_end(args);
  922.     }
  923. main()
  924.     {
  925.     int start = (printf("started\n"));
  926.     char buff[10];
  927.     print(buff, "%.2d %.2d %.2d", 1, 2, 3);
  928.     if (strcmp(buff, "01 02 03") == 0)
  929.         printf("success\n");
  930.     return 0;
  931.     }
  932.  
  933. /*  69: 4.9.9    fsetpos  fgetpos  (and  fpos_t  ) */
  934. #include <stdio.h>
  935. char name[1000];
  936. main()
  937.     {
  938.     int start = (printf("started\n"));
  939.     FILE *f;
  940.     fpos_t pos;
  941.     char buff[16];
  942.     tmpnam(name);
  943.     f = fopen(name, "w+");
  944.     fputs("first line\n", f);
  945.     fgetpos(f, &pos);
  946.     fputs("second line\n", f);
  947.     fputs("third line\n", f);
  948.     fsetpos(f, &pos);
  949.     fgets(buff, 16, f);
  950.     if (strcmp(buff, "second line\n") == 0)
  951.         printf("success\n");
  952.     fclose(f);
  953.     remove(name);
  954.     return 0;
  955.     }
  956.  
  957.  
  958. /*  70: 4.10     <stdlib.h> -- e.g. has size_t  [87/12] */
  959. #include <stdlib.h>
  960. #include <stdio.h>
  961. main()
  962.     {
  963.     int start = (printf("started\n"));
  964.     size_t n = 2;
  965.     if (n == 2)
  966.         printf("success\n");
  967.     return 0;
  968.     }
  969.  
  970. /*  71: 4.10.1   strtol, strtoul, strtod  [87/12] */
  971. #include <stdlib.h>
  972. #include <stdio.h>
  973. main()
  974.     {
  975.     int start = (printf("started\n"));
  976.     unsigned long ul;
  977.     char *p;
  978.     ul = strtoul("+0x010Y", &p, 0);
  979.     if (ul == 16L && *p == 'Y')
  980.         printf("success\n");
  981.     return 0;
  982.     }
  983.  
  984. /*  72: 4.10.4   system, atexit, getenv, EXIT_SUCCESS, EXIT_FAILURE  [86/12] */
  985. #include <stdlib.h>
  986. #include <stdio.h>
  987. void func()
  988.     {
  989.     if (EXIT_SUCCESS != EXIT_FAILURE)
  990.         printf("success\n");
  991.     }
  992. main()
  993.     {
  994.     int start = (printf("started\n"));
  995.     char *p = 0;
  996.     system("echo spawned >junk");
  997.     atexit(func);
  998.     p = getenv("");
  999.     return 0;
  1000.     }
  1001.  
  1002. /*  73: 4.10.6   div  ldiv */
  1003. #include <stdlib.h>
  1004. #include <stdio.h>
  1005. main()
  1006.     {
  1007.     int start = (printf("started\n"));
  1008.     div_t val;
  1009.     ldiv_t lval;
  1010.     val = div(-5, 3);
  1011.     lval = ldiv(-5L, 3L);
  1012.     if (val.quot == -1 && val.rem == -2 &&
  1013.         lval.quot == -1L && lval.rem == -2L)
  1014.         printf("success\n");
  1015.     return 0;
  1016.     }
  1017.  
  1018. /*  74: 4.11     <string.h> -- e.g. memset and strcmp */
  1019. #include <string.h>
  1020. #include <stdio.h>
  1021. main()
  1022.     {
  1023.     int start = (printf("started\n"));
  1024.     static char a[5] = "0123";
  1025.     memset(a, 'x', 4);
  1026.     if (strcmp(a, "xxxx") == 0)
  1027.         printf("success\n");
  1028.     return 0;
  1029.     }
  1030.  
  1031. /*  75: 4.11.2   memmove, strstr  [87/03] */
  1032. #include <string.h>
  1033. char *s = "0123456789";
  1034. #include <stdio.h>
  1035. main()
  1036.     {
  1037.     int start = (printf("started\n"));
  1038.     char *p;
  1039.     char q[11];
  1040.     p = strstr("testXYZtest", "XYZ");
  1041.     if (*p == 'X' && strstr(p, "") == p)
  1042.         {
  1043.         strcpy(q, s);
  1044.         memmove(q, q+1, 9);
  1045.         if (strcmp(q, "1234567899") ==0)
  1046.             {
  1047.             strcpy(q, s);
  1048.             memmove(q+1, q, 9);
  1049.             if (strcmp(q, "0012345678") == 0)
  1050.                 printf("success\n");
  1051.             }
  1052.         }
  1053.     return 0;
  1054.     }
  1055.  
  1056. /*  76: 4.11.6.2 strerror */
  1057. #include <string.h>
  1058. #include <stdio.h>
  1059. main()
  1060.     {
  1061.     int start = (printf("started\n"));
  1062.     if (strerror(0) != 0)
  1063.         printf("success\n");
  1064.     return 0;
  1065.     }
  1066.  
  1067. /*  77: 4.12     <time.h>   */
  1068. #include <time.h>
  1069. #include <stdio.h>
  1070. main()
  1071.     {
  1072.     int start = (printf("started\n"));
  1073.     char *p = NULL;
  1074.     int i = (sizeof(clock_t) + sizeof(time_t));
  1075.     if (i > 0)
  1076.         printf("success\n");
  1077.     return 0;
  1078.     }
  1079.  
  1080. /*  78: 4.12.2.2 difftime */
  1081. #include <time.h>
  1082. #include <stdio.h>
  1083. main()
  1084.     {
  1085.     int start = (printf("started\n"));
  1086.     struct tm time1, time2;
  1087.     time1.tm_isdst = time2.tm_isdst = 0;
  1088.     time1.tm_year = time2.tm_year = 88;
  1089.     time1.tm_mon = time2.tm_mon = 12;
  1090.     time1.tm_mday = time2.tm_mday = 25;
  1091.     time1.tm_hour = 7;
  1092.     time2.tm_hour = 8;
  1093.     time1.tm_min = time2.tm_min = 31;
  1094.     time1.tm_sec = 13;
  1095.     time2.tm_sec = 17;
  1096.     if (difftime(mktime(&time2), mktime(&time1)) == 3604.0)
  1097.         printf("success\n");
  1098.     return 0;
  1099.     }
  1100.  
  1101. /*  79: 4.12.3.5 strftime  */
  1102. #include <time.h>
  1103. #include <string.h>
  1104. #include <stdio.h>
  1105. main()
  1106.     {
  1107.     int start = (printf("started\n"));
  1108.     size_t nc;
  1109.     struct tm time1;
  1110.     char buff[500];
  1111.     time1.tm_isdst = 0;
  1112.     time1.tm_year = 88;
  1113.     time1.tm_mon = 11;    /* December */
  1114.     time1.tm_mday = 25;
  1115.     time1.tm_hour = 7;
  1116.     time1.tm_min = 31;
  1117.     time1.tm_sec = 13;
  1118.     nc = strftime(buff, 500, "%B %d, 19%y, %I:%M %p", &time1);
  1119.     if (nc == strlen(buff))
  1120.         printf("success\n");
  1121.     return 0;
  1122.     }
  1123.  
  1124.  /* THE REMAINING 22 ITEMS REQUIRE A FULL-SCALE VALIDATION SUITE ... */
  1125.  /*  80: 2.*      Full semantics: environment */
  1126.  /*  81: 2.1.2.3  sequence points */
  1127.  /*  82: 2.1.2.2  argv[0] is program-name or null-string */
  1128.  /*  83: 2.2.4.1  translation-time capacity limits */
  1129.  /*  84: 3.1.*    All required diagnostics: Lexical elements */
  1130.  /*  85: 3.1.*    Full syntax and semantics: Lexical elements */
  1131.  /*  86: 3.2.*    All required diagnostics: Conversions */
  1132.  /*  87: 3.2.*    Full syntax and semantics: Conversions */
  1133.  /*  88: 3.3.*    Full syntax and semantics: Expressions */
  1134.  /*  89: 3.3.*    All required diagnostics: Expressions */
  1135.  /*  90: 3.4.*    Full syntax and semantics: Constant expressions */
  1136.  /*  91: 3.4.*    All required diagnostics: Constant expressions */
  1137.  /*  92: 3.5.*    All required diagnostics: Declarations */
  1138.  /*  93: 3.5.*    Full syntax and semantics: Declarations */
  1139.  /*  94: 3.6.*    All required diagnostics: Statements */
  1140.  /*  95: 3.6.*    Full syntax and semantics: Statements */
  1141.  /*  96: 3.7.*    All required diagnostics: External definitions */
  1142.  /*  97: 3.7.*    Full syntax and semantics: External definitions */
  1143.  /*  98: 3.8.*    All required diagnostics: Preprocessing directives */
  1144.  /*  99: 3.8.*    Full syntax and semantics: Preprocessing directives */
  1145.  /* 100: 4.1.2    No reserved names in user name space */
  1146.  /* 101: 4.1.2    No user names in standard headers */
  1147.  
  1148.  /* THESE ITEMS ARE "THE 101 FEATURES" OF ANSI/ISO C.                    */
  1149.  /* Items 1-79 can be sampled with this Plum Hall Validation Sampler.    */
  1150.  /* Items 80-101 require a full-scale Validation Suite.                  */
  1151.  /* (Contact Plum Hall for information about the comprehensive tests     */
  1152.  /* embodied in the Plum Hall Validation Suite for C.)                   */
  1153.  /* This "Sampler" is not intended for any formal certification or       */
  1154.  /* validation work; it is intended only to provide an overall           */
  1155.  /* estimate of how close a compiler is to the soon-to-be ANSI Standard. */
  1156.  /* Copyright (c) 1988, Plum Hall Inc and Chiron Systems Inc.            */
  1157.  /* Permission is granted for reproduction and use of this "Sampler"     */
  1158.  /* provided that this notice is reproduced entirely.                    */
  1159.  /* Tom Plum, Plum Hall Inc, 609-927-3770,  uunet!plumhall!plum .        */
  1160.  /* Ralph Ryan, Chiron Systems Inc.                                      */
  1161.  /* With assistance from Don Gallagher and Scott Erlichman.        ...      */
  1162.  /* REVISIONS: 88/12/22 */
  1163.  /* Test 13:  f(start) -> *f(&start)  AND  f(int) -> f(int *) */
  1164.  /* Test 18:  In function f (after line 249), add  return 0; */
  1165.  /* Test 72:  On (now) line 988, change  succeed  to  success */
  1166.  /*           Also, on line 994 change to "echo spawned >junk" */
  1167.  /* Test 79:  On line 1111, change month to 11  (zero-origin ouch) */
  1168.  /* Tests 13 + 72 could have affected scoring; 18 + 79 are cosmetic */
  1169.  /* REVISIONS: 89/03/03, to become "sampler.89a" */
  1170.  /* Test 51:  Capture  errno  before calling  printf */
  1171.  /* REVISIONS: 89/04/07, to become "sampler.89b" */
  1172.  /* Test 55:  Add  #include <string.h>  , for  strncpy  and  strncmp  */
  1173.